%% Test Creation
PQ = PQ_Init(7);

track_tasks(1:20) = struct('type','','id',-1);
scan_tasks(1:20) = struct('type','','id',-1);
id_tasks(1:20) = struct('type','','id',-1);

for i = 1:20
  track_tasks(i) = struct('type','track','id',i);
  scan_tasks(i) = struct('type','scan','id',i);
  id_tasks(i) = struct('type','id','id',i);
end

%% Test Task Addition
tasks = [track_tasks scan_tasks id_tasks];
n = size(tasks, 2);

for i = 1:n
  [PQ, status] = PQ_Add_Task(PQ, tasks(i), 7);
  if ~status
    break;
  end
end

PQ1 = PQ;

%% Test Priority Change
for j = 1:20
  for i = 1:n
    if ceil(rand()*2) == 2
      [PQ, status] = PQ_Raise_Task_Priority(PQ, i);
    else
      [PQ, status] = PQ_Lower_Task_Priority(PQ, i);
    end
    if ~status
      break;
    end
  end
end

PQ2 = PQ;

%% Test Fetching Tasks
k = 1;
for p = 1:7
  for i = 1:n
    [task, status] = PQ_Fetch_Task(PQ, i, 8-p);
    if status
      Task(k) = task;
      priority(k) = 8-p;
      k = k + 1;
    end
  end
end

%% Test Changing Tasks
for i = 1:20
  scan_tasks = struct('type','scan','id',i+10);
  [PQ, status] = PQ_Update_Task(PQ, i+20, scan_tasks);
end

PQ3 = PQ;

%% Test Task Deletion
k = 1;
j(1:60) = 0;
for i = 1:n
  m = PQ_Size(PQ);
  j(k) = ceil(rand()*m);
  [PQ, status] = PQ_Remove_Task(PQ, j(k));
  if ~status
    break;
  else
    k = k + 1;
  end
end

PQ4 = PQ;